from pygame import *
from configparser import *
from math import sin

class Tool:

    def __init__(self):
        self.key_list = []
        self.keyint_str_list = []
        self.key_str = "qwertyuiopasdfghjklzxcvbnm"#26字母
        self.keyint_str = "1234567890"
        self.jp = "あいうえお"\
                   "かきくけこ"\
                   "さしすせそ"\
                   "たちつてと"\
                   "はひふへほ"\
                   "まみむめも"\
                   "なにぬねの"\
                   "らりるれろ"\
                   "やゆよ"\
                   "わを"\
                   "ん"\
                   "ざじずぜぞ"\
                   "だぢづでど"\
                   "ぱぴぷぺぽ"\
                   "ばびぶべぼ" \
                    "ぁぃぅぇぉ"
        self.jp_en = "a,i,u,e,o," \
                     "ka,ki,ku,ke,ko," \
                     "sa,si,su,se,so," \
                     "ta,ti,tu,te,to," \
                     "ha,hi,hu,he,ho," \
                     "ma,mi,mu,me,mo," \
                     "na,ni,nu,ne,no," \
                     "ra,ri,ru,re,ro," \
                     "ya,yu,yo," \
                     "wa,wo," \
                     "nn," \
                     "za,zi,zu,ze,zo," \
                     "da,di,du,de,do," \
                     "pa,pi,pu,pe,po," \
                     "ba,bi,bu,be,bo," \
                     "la,li,lu,le,lo"
        for i in self.key_str:
            self.key_list.append(i)
        for i in self.keyint_str:
            self.keyint_str_list.append(i)

    def change_cfg(self,filename,s,o,values):
        conf = ConfigParser()
        conf.read(filename)
        before_value = conf.get(s,o)
        conf.set(s,o,values)
        with open(filename,"w")as f:
            conf.write(f)
        if(__name__ == "__main__"):
            print("[system]:change {0} from {1}:{2} to {3}".format(before_value,s,o,values))


    def button(self,band:Surface,pos:tuple,eve_pos:tuple,name = "button"):
        #pos = (band.get_rect().left,band.get_rect().top)
        width = band.get_width()
        hieght = band.get_height()
        if(pos[0] <= eve_pos[0] <= pos[0]+width and pos[1] <= eve_pos[1] <= pos[1] + hieght):
            print("[system]:user button down: {0}".format(name))
            return True
        else:
            return False

    def pass_cfg(self,text:list):#加密
        end = ""
        for i in text:
            end = end + i + "|"
        return end[:len(end)-1]
        pass

    def read_cfg(self,text:str):#解密
        return text.split("|")

        pass

    def jp_to_en(self,jp_word:str):
        return self.jp_en[self.jp.index(jp_word)]
        pass

    def en_to_jp(self,jp_en_word:str):
        return self.jp[self.jp_en.split(",").index(jp_en_word)]
        pass

    def check_jp_to_en(self,jp_word:str):
        try:
            a = self.jp_en[self.jp.index(jp_word)]
            return True
        except:
            return False

    def check_en_to_jp(self,jp_en_word:str):
        try:
            a = self.jp[self.jp_en.split(",").index(jp_en_word)]
            return True
        except:
           return False

    def animation_sin(self,x,k,a):
        self.y = sin(k * x) * a
        return self.y


# if(__name__ == "__main__"):
#     print(Tool().jp_en.split(","))